﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.newsinfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    CKFinder.FileBrowser fileBrowser = new CKFinder.FileBrowser();
                    fileBrowser.BasePath = "../ckfinder/"; //设置CKFinder的基路径 
                    fileBrowser.SetupCKEditor(ckcontent);
                    Maticsoft.BLL.typeinfo bt = new BLL.typeinfo();
                    ddltype.DataSource = bt.GetAllList().Tables[0];
                    ddltype.DataTextField = "tname";
                    ddltype.DataValueField = "tid";
                    ddltype.DataBind();
                    int nid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(nid);
                }
            }
        }

        private void ShowInfo(int nid)
        {
            Maticsoft.BLL.newsinfo bll = new Maticsoft.BLL.newsinfo();
            Maticsoft.Model.newsinfo model = bll.GetModel(nid);
            this.lblnid.Text = model.nid.ToString();
            this.txtntitle.Text = model.ntitle;
            
            ckcontent.Text = model.ncontent;
            this.txtntime.Text = model.ntime.ToString();
            ddltype.SelectedValue = model.tid.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int nid = int.Parse(this.lblnid.Text);
            string ntitle = this.txtntitle.Text;
            
            string ncontent = ckcontent.Text;
            DateTime ntime = DateTime.Parse(this.txtntime.Text);
            int tid = int.Parse(ddltype.SelectedValue);


            Maticsoft.Model.newsinfo model = new Maticsoft.Model.newsinfo();
            model.nid = nid;
            model.ntitle = ntitle;
            
            model.ncontent = ncontent;
            model.ntime = ntime;
            model.tid = tid;

            Maticsoft.BLL.newsinfo bll = new Maticsoft.BLL.newsinfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
